GBML manual / Drawing

depth

Draw order: a HIGHER depth draws further back (drawn first, covered by anything with a lower depth). 0 is the default, already in front of anything pushed back on purpose.

Works differently on Game Boy - On the Game Boy depth only changes the drawing order of objects in a depth group that sorts by depth.

Works differently on Game Boy Color - On the Game Boy Color depth only changes the drawing order of objects in a depth group that sorts by depth.

On other consoles this differs: see Side by side and How the consoles differ.

Syntax

depth: real

Description

Draw order: a higher depth draws further back, so anything with a lower depth covers it. 0 is the default, already in front of anything deliberately pushed back. The most common use is a top-down y-sort - everything with a bigger y (further down the screen, so nearer the "camera" in a top-down game's own convention) should draw in front of everything with a smaller one.

Example

depth = -y;

The standard top-down y-sort: as y grows, depth shrinks, so anything lower on screen draws in front of anything higher - two characters crossing paths overlap correctly no matter which one is "in front" at any given moment. See Where the machine shows through's depth-bands diagram for how two close-together depths can still end up sharing one band, and drawing in creation order within it.

Text honors depth too

draw_text and draw_text_warped read depth exactly like every other call on this page - there is no exception for text. A draw_text call at a higher depth than a same-layer sprite or shape now draws behind it, the same as draw_sprite would, and two text calls (or a text call and anything else sharing its layer) are ordered by depth the same way, falling into the same bands and the same same-band creation-order tie-break as everything else (Where the machine shows through's "Depth is quantized into bands").

World-space draw_text/draw_text_warped is where this is easiest to put to use - a floating damage number can now be tucked behind another sprite (a light mask, an enemy standing over it) just by giving it a higher depth, the same as any other world-space drawing. The same two calls in a Draw GUI event honor depth too, but only ever against other GUI content: everything drawn in a Draw GUI event already sits on the screen layer, in front of the whole world whatever its depth, so no depth value puts a GUI draw behind the world - see bg_priority's "GUI content is always in front" section.

On the GBA

Quantised into bands because the hardware has a limited number of sort layers - many close-together depth values can share a band; do not expect one z_order per unit of depth.

See also: bg_prioritydraw_spritedraw_sprite_scaledWhere the machine shows through